package ar.com.photo_admin.service.security

import org.springframework.security.authentication.AbstractAuthenticationToken
import org.springframework.security.core.GrantedAuthority

class FacebookAuthenticationToken extends AbstractAuthenticationToken {

	Object principal
	String accessToken;

	public FacebookAuthenticationToken(Object principal, String accessToken) {
		super(null)
		this.principal = principal
		this.accessToken = accessToken
	}

	public FacebookAuthenticationToken(Object principal, String accessToken, Collection<? extends GrantedAuthority> authorities) {
		super(authorities)
		this.principal = principal
		this.accessToken = accessToken
		super.setAuthenticated(true) //since we throw illegal exceptions...call super
	}

	Object getCredentials() {
		return null
	}

	Object getPrincipal() {
		return principal
	}

	void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
		if(isAuthenticated)
			throw new IllegalArgumentException("Cannot set this token to trusted - use constructor containing GrantedAuthority[]s instead")

		super.setAuthenticated(false)
	}
}